package com.itheima.gen;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Random;
import java.util.function.Function;

public class Generator {


    public static String caseList(int size,
                                  Function<Integer, String[]> generator) {
        return caseList(size, generator, null);
    }

    public static String caseList(int size,
                                  Function<Integer, String[]> generator,
                                  Function<String[], String> toString) {
        return TestCaseGenerator.list(size, generator, toString);
    }


    public static <K, V> String caseMap(int size, Function<Integer, K> getKey, Function<K, V> getValue) {
        return TestCaseGenerator.map(size, getKey, getValue);
    }

    public static String word() {
        return StringGenerator.word();
    }

    public static String name() {
        return name(-1);
    }

    public static String name(int count) {
        return StringGenerator.name(count);
    }

    /**
     * 生成一个指定范围内的随机整数
     *
     * @param min 最小值 (包含)
     * @param max 最大值 (不包含)
     * @return 随机数
     */
    public static <T extends Number> T number(T min, T max) {
        return NumberGenerator.generate(min, max);
    }

    public static int randomInt(int min, int max) {
        return NumberGenerator.generate(min, max);
    }

    public static double randomDouble(double start, double end) {
        return NumberGenerator.generate(start, end);
    }

    public static <T> T randomSelect(T... args) {
        // Random select from args
        Random random = new Random();
        return args[random.nextInt(args.length)];
    }

    public static <T> List<T> array(int size, Function<Integer, T> generator) {
        return ArrayGenerator.generate(size, generator);
    }

    public static void main(String[] args) {
        final List<Double> array = array(10, i -> number(1.0, 3.0));
        System.out.println(array);
    }

    public static String randomDate(String format) {
        // 根据指定的格式生成随机日期字符串
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
        LocalDateTime time = LocalDateTime.of(
                number(1970, 2030), number(1, 13), number(1, 29),
                number(0, 24), number(0, 60), number(0, 60));

        return time.format(formatter);
    }

}
